﻿using Application.Dto;
using Application.IAppSrevices;
using AutoMapper;
using Domain.Entitys;
using Microsoft.AspNetCore.Mvc;

namespace UI.Controllers
{
    public class CFTKController : Controller
    {
        private readonly ICFTKService cFTKService;
        private readonly IMapper mapper;
        private readonly ICFSKService cFSKService;

        public CFTKController(ICFTKService cFTKService,IMapper mapper,ICFSKService cFSKService)
        {
            this.cFTKService = cFTKService;
            this.mapper = mapper;
            this.cFSKService = cFSKService;
        }

        public IActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 分页查询3级机构表数据
        /// </summary>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public IActionResult CFTKSelectFnYe(int currentPage, int pageSize)
        {
            FenYe<CFTK> fenYe = new FenYe<CFTK>()
            {
                CurrentPage = currentPage,
                PageSize = pageSize
            };
            cFTKService.CFTKSelectFenYe(fenYe);
            return Json(fenYe);
        }

        /// <summary>
        /// 删除3级机构表数据
        /// </summary>
        /// <param name="cFTK"></param>
        /// <returns></returns>
        [HttpDelete("CFTK/CFTKDeleteAsync")]
        public async Task<IActionResult> CFTKDeleteAsync(CFTKDeleteDao cFTK)
        {
            int num = await cFTKService.CFTKDeleteAsync(cFTK);
            return Json(num);
        }

        /// <summary>
        /// 跳转到3级机构表添加页面
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult CFTKInsert()
        {
            return View();
        }

        /// <summary>
        /// 查询2级结构表下拉框数据
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> CFSKSelectOpiton()
        {
            return Json(await cFSKService.CFSKSelectOption());
        }

        /// <summary>
        /// 添加3级结构表数据
        /// </summary>
        /// <param name="cFTKAddDto"></param>
        /// <returns></returns>
        [HttpPost("CFTK/CFTKInsertAsync")]
        public async Task<IActionResult> CFTKInsertAsync(CFTKAddDto cFTKAddDto)
        {
            int num = await cFTKService.CFTKInsertAsync(cFTKAddDto);
            return Json(num);
        }

        /// <summary>
        /// 跳转到修改页面
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult CFTKUpdate(int id)
        {
            TempData["id"] = id;
            return View();
        }

        /// <summary>
        /// 按id查询对应数据
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> CFTKSelectById()
        {
            int id = (int)TempData["id"];
            CFTK cFTK = await cFTKService.CFTKSelectById(id);
            return Json(cFTK);
        }

        /// <summary>
        /// 修改3级结构表数据
        /// </summary>
        /// <param name="cFTK"></param>
        /// <returns></returns>
        [HttpPut("CFTK/CFTKUpdateAsync")]
        public async Task<IActionResult> CFTKUpdateAsync(CFTK cFTK)
        {
            int num = await cFTKService.CFTKUpdateAsync(cFTK);
            return Json(num);
        }

        public async Task<IActionResult> CFTKSelectByCftid(string ftkid)
        {
            return Json(await cFTKService.CFTKSelectByCftid(ftkid));
        }

        /// <summary>
        /// 级联显示下拉框数据
        /// </summary>
        /// <returns></returns>
        public IActionResult Cascaders()
        {
            List<Cascader> cascaders = cFTKService.Cascaders();
            return Json(cascaders);
        }
        [HttpGet("CFTK/GetCFFKCFSKCFTK")]
        public async Task<IActionResult> GetCFFKCFSKCFTK()
        {
            return Json(await cFTKService.GetCFFKCFSKCFTK());
        }
    }
}
